package edu.umassd.visual.components;

import java.awt.Color;
import java.util.List;
import java.util.Map.Entry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import edu.umassd.raddacl.Observation;
import edu.umassd.visual.DataPoints;
import edu.umassd.visual.RADDACLDisplay;
import edu.umassd.visual.View;

/**
 * Draws data points as ellipses.
 * 
 * @author Dan Avila
 * 
 */
@Component("data")
public class DataAsEllipses implements Displayable<RADDACLDisplay>
{
	@Autowired
	private DataPoints points;

	@Autowired
	private View view;

	private int attrX = 0;
	private int attrY = 1;

	@Override
	public void display(RADDACLDisplay display)
	{
		try
		{
			for (Entry<Color, List<Observation>> entry : points.clusters())
			{
				for (Observation obs : entry.getValue())
				{
					int x = view.dataToCanvasX(points.getX(obs)).intValue();
					int y = view.dataToCanvasY(points.getY(obs)).intValue();

					display.fill(entry.getKey());
					display.ellipse(x, y, 20, 20);
				}
			}
		}
		catch (NullPointerException e)
		{
			e.printStackTrace();
		}
	}

	public void setAttributeY(int attribute)
	{
		if (attribute != attrX)
		{
			this.attrY = attribute;
		}
	}

	public void setAttributeX(int attribute)
	{
		if (attribute != attrY)
		{
			this.attrX = attribute;
		}
	}
}
